import Vue from 'vue'
import App from './App.vue'
import router from './router'

import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';

Vue.use(ElementUI,{size: "mini"});


Vue.config.productionTip = false



Vue.prototype.$clone = function (obj) {
  return JSON.parse(JSON.stringify(obj))
}
Vue.prototype.$post = function (url, data) {
  var t = this;
  // console.log(url)
  return new Promise(function (resolve, reject) {
    $.ajax({
      type:"POST",
      url:url,
      contentType:"application/json",
      data: JSON.stringify(data)
    }).then(r => {
      if(!r.success){
        let bool = false
        if(r.errMessage != null){
          bool = true
          t.$notify.error(r.errMessage)

        }
        reject(bool)
      } else {
        resolve(r.data)
      }
    }).fail(e => {
      reject(e)
    })
  });
}
Vue.prototype.$get = function (url, data) {
  var t = this;
  // console.log(url)
  return new Promise(function (resolve, reject) {
    $.ajax({
      type:"GET",
      url:url,
      data,
    }).then(r => {
      if(!r.success){
        t.$notify.error(r.errMessage)
        reject()
      } else {
        resolve(r.data)
      }
    }).fail(e => {
      reject(e)
    })
  });
}

window.$vue = new Vue({
  router,
  render: h => h(App)
}).$mount('#app')
